#include "appreciate.h"
#include "ui_appreciate.h"
#include <QMessageBox>
#include <QPainter>
#include <QTime>
#include <QTimer>


Appreciate::Appreciate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Appreciate)
{
    ui->setupUi(this);
    qsrand(QTime::currentTime().msec());
    timer = new QTimer(this);
    timer->setInterval(1000);
    timer->start();
    QObject::connect(timer,SIGNAL(timeout()),this,SLOT(repaint()));

    QObject::connect(ui->start,SIGNAL(clicked()),timer,SLOT(start()));
    QObject::connect(ui->stop,SIGNAL(clicked()),timer,SLOT(stop()));

}

Appreciate::~Appreciate()
{
    delete ui;
}


void Appreciate::paintEvent(QPaintEvent *)
{
    QPainter qp(this);
    /* 随机切换图片 */
    int num = qrand()%5 + 1;
    QString imgstr = ":/img/";
    imgstr += QString::number(num);
    imgstr += ".jpg";
    img.load(imgstr);
    qp.drawImage(0,0,img);
}
